package com.gange.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class BeanFactory {
    private static Properties properties = new Properties();
    static{
        InputStream resourceAsStream = BeanFactory.class.getClassLoader().getResourceAsStream("application.properties");
        try {
            properties.load(resourceAsStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    //工厂帮我们创建对象
    public static Object getBean(String name){
        String className = properties.getProperty(name);
        try {
            Class<?> aClass = Class.forName(className);
            return aClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
